//
//  UIBarButtonItem+LZFUIBarButtonItem.m
//  BuDeJie
//
//  Created by 梁梓烽 on 16/4/3.
//  Copyright © 2016年 liangzifeng. All rights reserved.
//

#import "UIBarButtonItem+LZFUIBarButtonItem.h"

@implementation UIBarButtonItem (LZFUIBarButtonItem)

//高亮状态类型的按钮
+(UIBarButtonItem *)itemWithImage:(UIImage *)image  highLightedImage:(UIImage *)highImage target:(id) target action:(SEL) action
{
    
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:image forState:UIControlStateNormal];
    
    [btn setImage:highImage forState:UIControlStateHighlighted];
    [btn sizeToFit];
    
    //解决按钮点解范围过大的问题
    UIView *view=[[UIView alloc]initWithFrame:btn.bounds];
    [view addSubview:btn];
 
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];

   return   [[UIBarButtonItem alloc]initWithCustomView:view];

}


//选中状态的按钮
+(UIBarButtonItem *)itemWithImage:(UIImage *)image  selectedImage:(UIImage *)highImage target:(id) target action:(SEL) action
{
    
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:image forState:UIControlStateNormal];
    
    [btn setImage:highImage forState:UIControlStateSelected];
    [btn sizeToFit];
    
    //解决按钮点解范围过大的问题
    UIView *view=[[UIView alloc]initWithFrame:btn.bounds];
    [view addSubview:btn];

    
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    return   [[UIBarButtonItem alloc]initWithCustomView:view];
    
}
@end
